package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.button.BusinessSystemMenuIdData;
import com.jinmdz.fmis.api.admin.model.button.ButtonSaveData;
import com.jinmdz.fmis.api.admin.service.ButtonService;
import com.jinmdz.fmis.api.api.model.common.IdData;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.button.ButtonListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 菜单按钮维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-18 17:22
 */
@Api(description = "菜单按钮维护信息相关接口")
@RestController()
@RequestMapping("/admin/button")
public class ButtonController extends BaseController {

    @Resource
    private ButtonService buttonService;

    /**
     * 根据菜单id加载表【business_system_menu_button】中保存的按钮数据
     *
     * @param data 菜单主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 17:25
     */
    @ApiOperation(value = "根据菜单id加载表【business_system_menu_button】中保存的按钮数据", notes = "根据菜单id加载表【business_system_menu_button】中保存的按钮数据")
    @PostMapping("/load-button-list-with-menu-id")
    public BaseResult<ArrayList<ButtonListItem>> loadButtonListWithMenuId(@RequestBody BusinessSystemMenuIdData data) {
        return resultHandler(userItem -> buttonService.loadButtonListWithMenuId(data));
    }


    /**
     * 根据按钮id加载表【business_system_menu_button】中保存的按钮数据
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 17:26
     */
    @ApiOperation(value = "根据按钮id加载表【business_system_menu_button】中保存的按钮数据", notes = "根据表【business_system_menu_button】中id加载按钮数据")
    @PostMapping("/load-button-with-id")
    public BaseResult<ButtonSaveData> loadButtonWithId(@RequestBody IdData data) {
        return resultHandler(data, userItem -> buttonService.loadButtonWithId(data));
    }

    /**
     * 保存按钮数据信息
     *
     * @param data 按钮数据
     * @return
     * @author LiCongLu
     * @date 2020-03-18 17:26
     */
    @ApiOperation(value = "保存按钮数据信息", notes = "保存按钮数据信息到表【business_system_menu_button】中")
    @PostMapping("/save-button")
    public BaseResult saveButton(@RequestBody ButtonSaveData data) {
        return resultHandler(data, userItem -> buttonService.saveButton(userItem, data));
    }

    /**
     * 删除按钮数据信息
     *
     * @param data 主键和数据版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-18 17:27
     */
    @ApiOperation(value = "删除按钮数据信息", notes = "从表【business_system_menu_button】中删除按钮数据信息")
    @PostMapping("/delete-button-with-id")
    public BaseResult deleteButtonWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> buttonService.deleteButtonWithId(userItem, data));
    }
}
